#import "YjHealthPlugin.h"
#import "YJDeviceManager.h"
#import "MJExtension.h"

@implementation YjHealthPlugin
#pragma mark - init
+ (YjHealthPlugin *)sharedInstance {
    static YjHealthPlugin *instance = nil;
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        instance = [[self alloc] init];
    });
    return instance;
}
- (instancetype)init {
    self = [super init];
    if (!self) {
        return nil;
    }
    return self;
}
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"yj_health_plugin"
            binaryMessenger:[registrar messenger]];
  YjHealthPlugin* instance = [YjHealthPlugin sharedInstance];
  [registrar addMethodCallDelegate:instance channel:channel];
    
    

    /// 监听通知事件//--------------------------------------监听通知事件
    YjHealthEventChannel *eventChannel = [[YjHealthEventChannel alloc] initWithMessenger: registrar.messenger];
      instance.eventChannel = eventChannel;
}

///  自动执行调用SDK方法
- (void)autoCallSdkMethod:(NSString *)method list:(NSArray *)list result:(FlutterResult)result {
    SEL selector = NSSelectorFromString([NSString stringWithFormat:@"%@",method]);
    if (![[YJDeviceManager sharedInstance].smartBandMgr respondsToSelector:selector]) {
        NSLog(@"[YJDeviceManager sharedInstance].smartBandMgr can not respondsToSelector:%s",selector);
        result(FlutterMethodNotImplemented);
        return ;
    }
//              NSLog(@"%s",selector);
    NSMethodSignature *signature = [[YJDeviceManager sharedInstance].smartBandMgr methodSignatureForSelector:selector];
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
    invocation.target = [YJDeviceManager sharedInstance].smartBandMgr;
    invocation.selector = selector;
    ///  参数处理
    if (list.count > 0) {
        /// 有参数需要处理
        NSMutableArray *arrayObjects = [[NSMutableArray alloc] init];
        for (int i = 0; i < list.count; i++) {
            NSDictionary *dic = list[i];
            /// 最外层数据类型包裹
            NSString *key = dic.allKeys.firstObject;
            if ([key isEqualToString:yjSDKClientParameterTypeModel]) {
                NSDictionary *parameter = dic[key];/// 是字典
                NSString *keyModelClassName = parameter.allKeys.firstObject;
                NSDictionary *value = parameter[keyModelClassName];
                /// 第二个参数为model类型 处理
                /// 如果是model类型的  就去转下 然后直接调用方法   dic[key] 取出model数据
                NSObject *model = [NSClassFromString(keyModelClassName) mj_objectWithKeyValues:value];
                [arrayObjects addObject:model];
            }
            else if ([key isEqualToString:yjSDKClientParameterTypeArrayModel]) {
                NSDictionary *parameter = dic[key];/// 是字典
                NSString *keyModelClassName = parameter.allKeys.firstObject;
                NSArray *valueList = parameter[keyModelClassName];
                NSMutableArray *arrModel = [NSClassFromString(keyModelClassName) mj_objectArrayWithKeyValuesArray:valueList];
                [arrayObjects addObject:arrModel];
            }
            else {
                /// 普通的字符串  非模型 不需要处理  parameter   /// parameter是字符串 int Bool
                id parameter = dic[key];
                [arrayObjects addObject:parameter];
            }
        }
        NSInteger arg1 = 0, arg2 = 0, arg3 = 0, arg4 = 0, arg5 = 0, arg6 = 0, arg7 = 0, arg8 = 0, arg9 = 0, arg10 = 0;
        NSInteger numNSIntegerFlag = 0;
        CGFloat frg1 = 0.0, frg2 = 0.0, frg3 = 0.0, frg4 = 0.0, frg5 = 0.0;
        NSInteger numCGFloatFlag = 0;
        ///  处理完了数据  最后进行调用
        for (int i = 0; i < arrayObjects.count; i++) {
            id object = arrayObjects[i];
            /// 2 + i  是从2开始的  前0 1 已经被系统占用  self aaa
            if ([object isKindOfClass:[NSNumber class]]) {
                if (strcmp([object objCType], @encode(double)) == 0){
                    // 如果 flutter 端传过来的是double类型   直接转化成CGFloat 给SDK
                    numCGFloatFlag ++;
                    if (numCGFloatFlag == 1) {
                        frg1 = [object integerValue];
                        [invocation setArgument:&frg1 atIndex:i + 2];
                    } else if (numCGFloatFlag == 2) {
                        frg2 = [object integerValue];
                        [invocation setArgument:&frg2 atIndex:i + 2];
                    } else if (numCGFloatFlag == 3) {
                        frg3 = [object integerValue];
                        [invocation setArgument:&frg3 atIndex:i + 2];
                    } else if (numCGFloatFlag == 4) {
                        frg4 = [object integerValue];
                        [invocation setArgument:&frg4 atIndex:i + 2];
                    } else if (numCGFloatFlag == 5) {
                        frg5 = [object integerValue];
                        [invocation setArgument:&frg5 atIndex:i + 2];
                    }
                    
                } else {
                    // 如果 flutter 端传过来的是int类型   直接转化成NSInteger 给SDK
                    numNSIntegerFlag ++;
                    if (numNSIntegerFlag == 1) {
                        arg1 = [object integerValue];
                        [invocation setArgument:&arg1 atIndex:i + 2];
                    } else if (numNSIntegerFlag == 2) {
                        arg2 = [object integerValue];
                        [invocation setArgument:&arg2 atIndex:i + 2];
                    } else if (numNSIntegerFlag == 3) {
                        arg3 = [object integerValue];
                        [invocation setArgument:&arg3 atIndex:i + 2];
                    } else if (numNSIntegerFlag == 4) {
                        arg4 = [object integerValue];
                        [invocation setArgument:&arg4 atIndex:i + 2];
                    } else if (numNSIntegerFlag == 5) {
                        arg5 = [object integerValue];
                        [invocation setArgument:&arg5 atIndex:i + 2];
                    } else if (numNSIntegerFlag == 6) {
                        arg6 = [object integerValue];
                        [invocation setArgument:&arg6 atIndex:i + 2];
                    } else if (numNSIntegerFlag == 7) {
                        arg7 = [object integerValue];
                        [invocation setArgument:&arg7 atIndex:i + 2];
                    } else if (numNSIntegerFlag == 8) {
                        arg8 = [object integerValue];
                        [invocation setArgument:&arg8 atIndex:i + 2];
                    } else if (numNSIntegerFlag == 9) {
                        arg9 = [object integerValue];
                        [invocation setArgument:&arg9 atIndex:i + 2];
                    } else if (numNSIntegerFlag == 10) {
                        arg10 = [object integerValue];
                        [invocation setArgument:&arg10 atIndex:i + 2];
                    }
                }

            } else {
                [invocation setArgument:&object atIndex:i + 2];
            }
        }
        [invocation invoke];
    } else {
        ///  没有参数处理 直接调用方法
        [invocation invoke];
    }
    //返回值一定要是对象类型，基本类型 int, float ,double 等需要封装成NSNumber，id是对象，在堆里面，基本数据类型在字符常亮区，需要用一个指针指向。
    id __unsafe_unretained returnValue = nil;
    if (signature.methodReturnLength != 0) {//有返回值
        //获得返回值类型
        const char *returnType = signature.methodReturnType;
        //如果返回值为对象，那么为变量赋值
        if(!strcmp(returnType, @encode(id))){
            //将返回值赋值给returnValue
            [invocation getReturnValue:&returnValue];
            /// 如果是model  returnValue在这里做判断转化
        } else {
            //如果返回值为普通类型NSInteger  BOOL
            //返回值长度
            NSUInteger length = [signature methodReturnLength];
            //根据长度申请内存
            void *buffer = (void *)malloc(length);
            //为变量赋值
            [invocation getReturnValue:buffer];
            if(!strcmp(returnType, @encode(BOOL))) {
                returnValue = [NSNumber numberWithBool:*((BOOL*)buffer)];
            }
            else if(!strcmp(returnType, @encode(NSInteger))){
                returnValue = [NSNumber numberWithInteger:*((NSInteger*)buffer)];
            }
            else if(!strcmp(returnType, @encode(int))){
                returnValue = [NSNumber numberWithInt:*((int*)buffer)];
            }
            else if(!strcmp(returnType, @encode(float))){
                returnValue = [NSNumber numberWithFloat:*((float*)buffer)];
            }
            else if(!strcmp(returnType, @encode(double))){
                returnValue = [NSNumber numberWithDouble:*((double*)buffer)];
            }
        }
        result(returnValue);
    }
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"sendData" isEqualToString:call.method]) {
      if ([call.arguments isKindOfClass:[NSDictionary class]] && [(NSDictionary *)call.arguments[@"data"] isKindOfClass:[NSDictionary class]] ) {
          NSDictionary *data = (NSDictionary *)call.arguments[@"data"];
          NSString *name = data[@"name"];
          NSInteger tag = 0;
          if (data[@"tag"] != nil) {
               tag = [data[@"tag"] integerValue];
          }
          NSDictionary *arguments = (NSDictionary *)data[@"arguments"];
          if ([name isEqualToString:yjSDKClientTypeName]) {
              NSString *method = data[@"method"];
              if ([method containsString:@"_"]) {
                  //表明还有其他参数需要在方法名称后面加 :   _替换成:
                  NSString *str = method;
                  method = [str stringByReplacingOccurrencesOfString:@"_" withString:@":"];
              }
              NSLog(@"%@",method);
              NSLog(@"%@",arguments);
              NSArray *list = arguments[@"list"];
              if (tag == connectUTEModelDevices) {
                  NSDictionary *dic = list.firstObject;
                  /// 自定义处理
                  NSLog(@"点击了链接蓝牙");
                  [YjHealthPlugin sharedInstance].identifier = dic[@"address"];
                  [[YJDeviceManager sharedInstance] connect];
              } else if (tag == disConnectUTEModelDevices) {
                  /// 自定义处理
                  NSLog(@"点击了断开蓝牙");
                  [[YJDeviceManager sharedInstance] disconnect];
              }
              else {
                  ///  自动执行调用SDK方法
                  [self autoCallSdkMethod:method list:list result:result];
              }
              result(0);
          } else if ([name isEqualToString:yjUTECallBackTypeName]) {
              if (tag == yjUTECallBackTypeTime) {
                  [self onClickUTEOption:UTEOptionSyncTime];
              } else if (tag == yjUTECallBackTypeBattery) {
                  /// 获取电池
                  [self onClickUTEOption:UTEOptionReadDevicesBattery];
              } else if (tag == yjUTECallBackTypeDeviceInfo) {
                  /// 设置用户信息
                  NSDictionary *dic = arguments;
                  UTEModelDeviceInfo *info = [UTEModelDeviceInfo mj_objectWithKeyValues:dic];
                  [[YJDeviceManager sharedInstance].smartBandMgr setUTEInfoModel:info];
              } else if (tag == yjUTECallBackTypeLongSit) {
                  ///  打开久坐
                  NSInteger time = [arguments[@"time"] integerValue];
                  [[YJDeviceManager sharedInstance].smartBandMgr setUTESitRemindOpenTime:time];
              } else if (tag == yjUTECallBackTypeLongSitClose) {
                  ///  关闭久坐
                  [[YJDeviceManager sharedInstance].smartBandMgr setUTESitRemindClose];
//                  NSDictionary *dic = @{};
//                  [[YjHealthPlugin sharedInstance] sendToFlutterName:yjDevice tag:YJDeviceTypeLongSitClose dict:dic];
              } else if (tag == yjUTECallBackTypeLongSetWeather) {
                  /// 设置7天天气
                  NSArray *list = arguments[@"list"];
                  NSMutableArray *arr = [UTEModelWeather mj_objectArrayWithKeyValuesArray:list];
                  [[YJDeviceManager sharedInstance].smartBandMgr sendUTESevenWeather:arr];
              } else if (tag == yjUTECallBackTypeDotDisturbMode) {
                  //设置勿扰时间
                  NSString *startTime = arguments[@"startTime"];
                  NSString *endTime = arguments[@"endTime"];
                  [[YJDeviceManager sharedInstance].smartBandMgr sendUTEAllTimeSilence:UTESilenceTypePhone|UTESilenceTypeMessage
                                           exceptStartTime:startTime
                                           endTime:endTime
                                           except:YES];
              } else if (tag == yjUTECallBackTypeTel) {
                  /// 打电话
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSocialNotification || [YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSocialNotification2) {
                      [self onClickAppMoreRemind:UTEDeviceRemindOpen];
                  }else{
                      [self onClickUTEOption:UTEOptionOpenRemindMore];
                  }
              } else if (tag == yjUTECallBackTypeLanguage) {
                  /// 设置语言
                  UTESmartBandClient *blueMgr = [UTESmartBandClient sharedInstance];
                  if(blueMgr.connectedDevicesModel.isHasMultiLanguage){
                      if(blueMgr.connectedDevicesModel.isHasLanguageSwitchDirectly){
                          if(blueMgr.connectedDevicesModel.isHasReadSupportLanguage){
                              //先调用这个方法查看设备支持多少种语言设置，否则APP发送了语言指令，设备不支持的话，设备无任何变化
                              [[YJDeviceManager sharedInstance].smartBandMgr readDeviceLanguageSupport:^(UTEDeviceLanguage currentLanguage, NSArray<NSNumber *> * _Nullable supports) {
                                      BOOL hasSupportLanguage = NO;
                                      UTEDeviceLanguage langIndex = UTEDeviceLanguageChinese;
                                   for (NSNumber *numLang in supports) {
                                        if (numLang.integerValue == langIndex) {
                                                 hasSupportLanguage = YES;
                                                 break;
                                         }
                                   }
                                   if (hasSupportLanguage) {
                                       NSLog(@"设备支持当前语言--------发送快捷序号切换");
                                      [[YJDeviceManager sharedInstance].smartBandMgr setUTELanguageSwitchDirectly:langIndex];
                                   }else{
                                       NSLog(@"设备不支持当前语言-------发送默认语言(英文)");
                                      [[YJDeviceManager sharedInstance].smartBandMgr setUTELanguageSwitchDirectly:UTEDeviceLanguageOther];
                                   }
                              }];
                          }else{
                              NSLog(@"设备不支持 读取设备内部支持多少种语言，因此只能直接调用方法设置语言A。如果设备不支持语言A，那么设备无任何改变");
                              [[YJDeviceManager sharedInstance].smartBandMgr setUTELanguageSwitchDirectly:UTEDeviceLanguageChinese];
                          }
                      }else{
                          NSLog(@"设备不支持 语言快捷设置, 因此需要每个属性都要赋值文字");
                          UTEModelDeviceInterface *model = [[UTEModelDeviceInterface alloc] init];
                          model.num1Step = @"Step";
                          model.num2KM = @"km";
                          [[YJDeviceManager sharedInstance].smartBandMgr setUTELanguageInterface: model];
                      }
                  }else{
                      NSLog(@"设备不支持 语言设置");
                  }
              } else if (tag == yjUTECallBackTypeAlarm) {
                  /// 设置闹钟
                  NSArray *list = arguments[@"list"];
                  NSMutableArray *arr = [UTEModelAlarm mj_objectArrayWithKeyValuesArray:list];
                  [[YJDeviceManager sharedInstance].smartBandMgr setUTEAlarmArray:arr vibrate:5];
              }
          } else if ([name isEqualToString:yjSyncDataTypeName]) {
              
              if (tag == yjSyncDataTypeConnect) {
                  [YjHealthPlugin sharedInstance].identifier = arguments[@"address"];
                  [[YJDeviceManager sharedInstance] connect];
              } else if (tag == yjSyncDataTypeDisconnect) {
                  [[YJDeviceManager sharedInstance] disconnect];
              } else if (tag == yjSyncDataTypeStep) {
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasDataStatus) {
                      [self onClickSyncDataCustom:UTEDeviceDataTypeSteps];
                  }else{
                      [self onClickUTEOption:UTEOptionSyncAllStepsData];
                  }
              } else if (tag == yjSyncDataTypeSleep) {
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasDataStatus) {
                      [self onClickSyncDataCustom:UTEDeviceDataTypeSleep];
                  }else{
                      [self onClickUTEOption:UTEOptionSyncAllSleepData];
                  }
              } else if (tag == yjSyncDataTypeHRM) {
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasDataStatus) {
                      [self onClickSyncDataCustom:UTEDeviceDataTypeHRM24];
                  } else{
                      [self onClickUTEOption:UTEOptionSyncAllHRMData];
                  }
              } else if (tag == yjSyncDataTypeBlood) {
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasDataStatus) {
                      [self onClickSyncDataCustom:UTEDeviceDataTypeBlood];
                  } else {
                      [self onClickUTEOption:UTEOptionSyncAllBloodData];
                  }
              } else if (tag == yjSyncDataTypeSaO2) {
                  [self onClickUTEOption:UTEOptionSyncAllBloodOxygenData];
              } else if (tag == yjSyncDataTypeBodyTemperature) {
                  NSString *startTime = arguments[@"startTime"];
                  [[YJDeviceManager sharedInstance].smartBandMgr syncBodyTemperature:startTime];
              }
              /*
              if (tag == UTESyncTypeTime) {
              } else if (tag == UTESyncTypeStep) {
              } else if (tag == UTESyncTypeSleep) {
              } else if (tag == UTESyncTypeHRM) {
              } else if (tag == UTESyncType24HRM) {
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasDataStatus) {
                      [self onClickSyncDataCustom:UTEDeviceDataTypeHRM24];
                  } else {
                      [self onClickUTEOption:UTEOptionSyncAllHRMData];
                  }
              } else if (tag == UTESyncTypeBlood) {
              } else if (tag == UTESyncTypeSaO2) {
              } else if (tag == UTESyncTypeBodyFat) {
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasDataStatus) {
                      [self onClickSyncDataCustom:UTEDeviceDataTypeBodyFat];
                  } else {
                      [self onClickUTEOption:UTEOptionSyncBodyFat];
                  }
              } else if (tag == UTESyncTypeECG) {
                  [self onClickUTEOption:UTEOptionSyncECG];
              } else if (tag == UTESyncTypeSportGPS) {
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasDataStatus) {
                      [self onClickSyncDataCustom:UTEDeviceDataTypeGPS];
                  } else {
                      [self onClickSyncGPSData];
                  }
              } else if (tag == UTESyncTypeSkip) {
                  [self onClickUTEOption:UTEOptionSyncSkipData];
              } else if (tag == UTESyncTypeSwim) {
                  [self onClickUTEOption:UTEOptionSyncSwimData];
              } else if (tag == UTESyncTypeBall) {
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasDataStatus) {
                      [self onClickSyncDataCustom:UTEDeviceDataTypeBall];
                  } else{
                      [self onClickUTEOption:UTEOptionSyncBallData];
                  }
              } else if (tag == UTESyncTypeAllSport) {
                  [self onClickSyncUTESportModelCustom];
              } else if (tag == UTESyncTypeBodyTemperature) {
              }
              */
          } else if ([name isEqualToString:yjCustomTypeName]) {
              if (tag == yjCustomTypeInitSdk) {
                  /// 初始化SDK
                  [[YJDeviceManager sharedInstance] initSdk];
              } else if (tag == yjCustomTypeScan) {
                  [[YJDeviceManager sharedInstance] startScanDevices];
              } else if (tag == yjCustomTypeStop) {
                  [[YJDeviceManager sharedInstance] stopScanDevices];
              } else if (tag == yjCustomTypeFindPhone) {
                  
                  
              } else if (tag == yjCustomTypeMusicPlay) {
                  
                  
              } else if (tag == yjCustomTypeMusicLast) {
                  
                  
              } else if (tag == yjCustomTypeMusicNext) {
                  
                  
              } else if (tag == yjCustomTypeDeviceUnit) {
                  /// 设置单位
                  int unit = [arguments[@"unit"] intValue];
                  if (unit == 0) {
                      [[YJDeviceManager sharedInstance].smartBandMgr setUTEOption:UTEOptionUnitInch];
                  } else if (unit == 1) {
                      [[YJDeviceManager sharedInstance].smartBandMgr setUTEOption:UTEOptionUnitMeter];
                  }
              }

          }
          
          /*
          else if ([name isEqualToString:kUTETestMethod]) {
              if (tag == UTETestTypeSetStaticHRM) {
                  
                  [self onClickUTEOption:UTEOptionHeartSwitchStatic];
                  
              }else if (tag == UTETestTypeSetDynamicHRM) {
                  
                  [self onClickUTEOption:UTEOptionHeartSwitchDynamic];
                  
              }else if (tag == UTETestTypeStartHRM) {
                  
                  [self onClickUTEOption:UTEOptionHeartDetectingStart];
                  
              }else if (tag == UTETestTypeStopHRM) {
                  
                  [self onClickUTEOption:UTEOptionHeartDetectingStop];
                  
              }else if (tag == UTETestTypeAutomaticHRM) {
                  
                  [[YJDeviceManager sharedInstance].smartBandMgr setUTEHeartAuto:YES time:1];
                  
              }else if (tag == UTETestTypeOpen24HRM) {
                  
                  [self onClickUTEOption:UTEOptionOpen24HourHRM];
                  
              }else if (tag == UTETestTypeClose24HRM) {
                  
                  [self onClickUTEOption:UTEOptionClose24HourHRM];
                  
              }else if (tag == UTETestTypeStartBlood) {
                  
                  [self onClickUTEOption:UTEOptionBloodDetectingStart];
                  
              }else if (tag == UTETestTypeStopBlood) {
                  
                  [self onClickUTEOption:UTEOptionBloodDetectingStop];
                  
              }else if (tag == UTETestTypeStartSaO2) {
                  
                  [self onClickUTEOption:UTEOptionBloodOxygenDetectingStart];
                  
              }else if (tag == UTETestTypeStopSaO2) {
                  
                  [self onClickUTEOption:UTEOptionBloodOxygenDetectingStop];
                  
              }else if (tag == UTETestTypeStartBodyFat) {
                  
                  [self onClickTestBodyFat:YES];
                  
              }else if (tag == UTETestTypeStopBodyFat) {
                  
                  [self onClickTestBodyFat:NO];
                  
              }else if (tag == UTETestTypeStartECG) {
                  
                  [self onClickTestECG:YES];
                  
              }else if (tag == UTETestTypeStopECG) {
                  
                  [self onClickTestECG:NO];
                  
              }
          } else if ([name isEqualToString:kUpdateFirmware]) {
              if (tag == UTEFirmwareTypeCheck) {
                  
                  [self onClickUpdateFirmwareCheck];
                  
              }else if (tag == UTEFirmwareTypeUpdate){
                  
                  [self onClickUpdateFirmwareUpate];
                  
              }
          } else if ([name isEqualToString:kAppRemind]) {
              if (tag == UTERemindTypeOpenQQ) {
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSocialNotification || [YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSocialNotification2) {
                      [self onClickAppQQRemind:UTEDeviceRemindOpen];
                  }else{
                      [self onClickUTEOption:UTEOptionOpenRemindQQ];
                  }
              }else if (tag == UTERemindTypeCloseQQ){
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSocialNotification || [YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSocialNotification2) {
                      [self onClickAppQQRemind:UTEDeviceRemindClose];
                  }else{
                      [self onClickUTEOption:UTEOptionCloseRemindQQ];
                  }
              }else if (tag == UTERemindTypeOpenOther){
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSocialNotification || [YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSocialNotification2) {
                      [self onClickAppMoreRemind:UTEDeviceRemindOpen];
                  }else{
                      [self onClickUTEOption:UTEOptionOpenRemindMore];
                  }
              }else if (tag == UTERemindTypeCloseOther){
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSocialNotification || [YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSocialNotification2) {
                      [self onClickAppMoreRemind:UTEDeviceRemindClose];
                  }else{
                      [self onClickUTEOption:UTEOptionCloseRemindMore];
                  }
              }else if (tag == UTERemindTypeOpenSit){
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSitRemindDuration){
                      [self onClickSitRemind:YES];
                  }else{
                      [[YJDeviceManager sharedInstance].smartBandMgr setUTESitRemindOpenTime:60];
                  }
              }else if (tag == UTERemindTypeCloseSit){
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSitRemindDuration){
                      [self onClickSitRemind:NO];
                  }else{
                      [[YJDeviceManager sharedInstance].smartBandMgr setUTESitRemindClose];
                  }
              }
          } else if ([name isEqualToString:kAboutSport]) {
              if(tag == UTESportTypeReadStatus){
                  [self readUTESportModelStatus];
              }else if(tag == UTESportTypeStartCycling){
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSportHRM || [YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasHeadsetHRM) {
                      [self setUTEBicycleSportModel:YES];
                  }else{
                      [self onClickUTEOption:UTEOptionOpenBicycle];
                  }
              }else if(tag == UTESportTypeStopCycling){
                  if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSportHRM || [YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasHeadsetHRM) {
                      [self setUTEBicycleSportModel:NO];
                  }else{
                      [self onClickUTEOption:UTEOptionCloseBicycle];
                  }
              }else if(tag == UTESportTypePauseCycling){
                  [self setUTBicycleESportModelPause];
              }else if(tag == UTESportTypeContinueCycling){
                  [self setUTESportModelContinue];
              }else if(tag == UTESportTypeCyclingSameData){
                  [self setUTESportModelInfo];
              }
              
          } else if ([name isEqualToString:kAboutDial]) {
              if (tag == UTEDialTypeReadDialInfo) {
                  [self readUTEDisplayInfoFormDevice];
              }else if (tag == UTEDialTypeReadOnlineDial) {
                  [self getUTEDisplayInfoFormServer];
              }else if (tag == UTEDialTypeSyncDial) {
                  NSString *path = @"/var/mobile/Containers/Data/Application/xxxxx/SH0AV0000564.bin";
                  NSData *data = [NSData dataWithContentsOfFile:path];
                  [self sendUTEDisplayDataToDevice:data];
              }else if (tag == UTEDialTypeLoadLocalDial) {
                  [self getUTECustomDialDefualtInfo];
              }else if (tag == UTEDialTypeLoadOnlineCustomDial) {
                  [self getUTECustomDialInfoFromServer];
              }else if (tag == UTEDialTypeOnlineCustomDialModel){
                  [self getUTECustomDialInfoFromUnzippedPath];
              }else if (tag == UTEDialTypeChangeOnlineCustomDial){
                  [self changeUTEDialBackgroundImage];
              }else if (tag == UTEDialTypeSyncCustomDial){
//                  [self sendUTEDisplayDataToDevice:self.localDialInfoModel.dataBin];
              }
          } else if ([name isEqualToString:kAboutRespiration]) {
              if (tag == UTERespirationRateTypeStartTest) {
                  [self startTestRespirationRate];
              }else if(tag == UTERespirationRateTypeStopTest){
                  [self stopTestRespirationRate];
              }else if(tag == UTERespirationRateTypeReadStatus){
                  [self readRespirationRateTestStatus];
              }else if(tag == UTERespirationRateTypeSync){
                  [self onClickUTEOption:UTEOptionSyncAllRespirationData];
              }else if(tag == UTERespirationRateTypeOpenTime){
                  [self startRespirationRateCustomTestTime];
              }else if(tag == UTERespirationRateTypeCloseTime){
                  [self closeRespirationRateCustomTestTime];
              }
          } else if ([name isEqualToString:kOther]) {
              if (tag == UTEOtherTypeSetAlarm) {
                  [self setDevicesAlarm];
              }else if(tag == UTEOtherTypeSetPersonalInfo){
                  [self setHeightWeightInfo];
              }else if(tag == UTEOtherTypeReSetDevice){
                  [self onClickUTEOption:UTEOptionDeleteDevicesAllData];
              }else if(tag == UTEOtherTypeDontDisturbMode){
                  /// 设置勿扰模式
                  NSString *startTime = arguments[@"startTime"];
                  NSString *endTime = arguments[@"endTime"];
                  [[YJDeviceManager sharedInstance].smartBandMgr sendUTEAllTimeSilence:UTESilenceTypePhone|UTESilenceTypeMessage
                                           exceptStartTime:startTime
                                           endTime:endTime
                                           except:YES];

              }else if(tag == UTEOtherTypeSetWeather){
                  /// 设置7天天气
                  NSArray *list = arguments[@"list"];
                  NSMutableArray *arr = [UTEModelWeather mj_objectArrayWithKeyValuesArray:list];
                  [[YJDeviceManager sharedInstance].smartBandMgr sendUTESevenWeather:arr];

              }else if(tag == UTEOtherTypeCustomDeviceText){
                  [self setDevicesInterfaceText];
              }else if(tag == UTEOtherTypeSleepCorrect){
                  [self adjustSleepInfo];
              }else if(tag == UTEOtherTypeCustomSleep){
                  [self adjustSleepInfoNight];
              }else if(tag == UTEOtherTypeCustomNapSleep){
                  [self adjustSleepInfoSiesta];
              }else if(tag == UTEOtherTypeFindDevice){
                  [self onClickUTEOption:UTEOptionFindBand];
              }else if(tag == UTEOtherTypeCustomDataSend){
                  [self sendCustomData];
              }else if(tag == UTEOtherTypeOpenCameraMode){
                  [self onClickUTEOption:UTEOptionOpenCameraMode];
              }else if(tag == UTEOtherTypeCloseCameraMode){
                  [self onClickUTEOption:UTEOptionCloseCameraMode];
              }else if(tag == UTEOtherTypeMeter_12){
                  [self onClickUTEOption:UTEOptionUnitMeter_12];
              }else if(tag == UTEOtherTypeInch_12){
                  [self onClickUTEOption:UTEOptionUnitInch_12];
              }else if(tag == UTEOtherTypeMeter_24){
                  [self onClickUTEOption:UTEOptionUnitMeter_24];
              }else if(tag == UTEOtherTypeInch_24){
                  [self onClickUTEOption:UTEOptionUnitInch_24];
              }else if(tag == UTEOtherTypeReadBatteryPower){
                  [self onClickUTEOption:UTEOptionReadDevicesBattery];
              }else if(tag == UTEOtherTypeOpenFindPhone){
                  [self onClickUTEOption:UTEOptionFindPhoneFunctionOpen];
              }else if(tag == UTEOtherTypeCloseFindPhone){
                  [self onClickUTEOption:UTEOptionFindPhoneFunctionClose];
              }else if(tag == UTEOtherTypeShutdown){
                  [self onClickUTEOption:UTEOptionShutdown];
              }else if(tag == UTEOtherTypeStartCalibrationHRM){
                  [self onClickUTEOption:UTEOptionHRMCalibrateStart];
              }else if(tag == UTEOtherTypeCalibrationHRMDefault){
                  [self onClickUTEOption:UTEOptionHRMCalibrateDefault];
              }else if(tag == UTEOtherTypeStartCalibrationHand){
                  [self onClickUTEOption:UTEOptionRaiseHandCalibrateStart];
              }else if(tag == UTEOtherTypeCalibrationHandDefault){
                  [self onClickUTEOption:UTEOptionRaiseHandCalibrateDefault];
              }else if(tag == UTEOtherTypeReSetTempCalibration){
                  [self onClickUTEOption:UTEOptionResetBodyTemperature];
              }else if(tag == UTEOtherTypeClearAllBodyTemp){
                  [self onClickUTEOption:UTEOptionClearBodyTemperature];
              }else if(tag == UTEOtherTypeReadUV){
                  [[YJDeviceManager sharedInstance].smartBandMgr readUTEDeviceUV:^(NSInteger value) {
                      NSLog(@"UV = %ld",(long)value);
                  }];
              }else if(tag == UTEOtherTypeSetMenstruation){
                  [self sendMenstruationRemind];
              }else if(tag == UTEOtherTypeCustomDeviceUI){
                  [self setUTEDeviceCustomUIStatus];
              }else if(tag == UTEOtherTypeCustomContentSend){
                  [self sendUTECustomMsg];
              }else if(tag == UTEOtherTypeReadDeviceVersion){
                  [self readUTEDeviceVersion];
              }else if(tag == UTEOtherTypeReadDeviceAddress){
                  [self readUTEDeviceAddress];
              }else if(tag == UTEOtherTypeReadDeviceLanguage){
                  [self readDeviceLanguage];
              }else if(tag == UTEOtherTypeCalibrationBodyTemp){
                  [self calibrateBodyTemp];
              }else if(tag == UTEOtherTypeAutomaticTestBodyTemp){
                  [self setBodyTemperatureAutoTest];
              }else if(tag == UTEOtherTypeAutomaticTestBodyTempPeriod){
                  [self setBodyTemperatureAutoTestDuration];
              }else if(tag == UTEOtherTypeAutomaticTestBodyTempAlarm){
                  [self setBodyTemperatureAlarmOpen];
              }else if(tag == UTEOtherTypeReadCurrentBodyTemp){
                  [self readBodyTemperatureCurrent];
              }else if(tag == UTEOtherTypeReadConnectDevice){
                  [self retrieveConnectedDeviceWithServers];
              }else if(tag == UTEOtherTypeAutoTestBloodOxygen){
                  [self setBloodOxygenAutoTest];
              }else if(tag == UTEOtherTypeAutoTestDurationBloodOxygen){
                  [self setBloodOxygenAutoTestDuration];
              }else if(tag == UTEOtherTypeReadSupport){
                  [self getSportSupport];
              }else if(tag == UTEOtherTypeReadSportCurrentDisplay){
                  [self getSportCurrent];
              }else if(tag == UTEOtherTypeSetSportCurrentDisplay){
                  [self setSportCurrent];
              }

          }
          */
      } else {
          result(FlutterMethodNotImplemented);
      }
  } else {
    result(FlutterMethodNotImplemented);
  }
    /// 所有方法均有返回值
    result(0);
}

- (void)sendToFlutterName:(NSString *)name tag:(NSInteger)tag dict:(NSDictionary *)dict {
    NSDictionary *dic = @{@"name":name, @"tag":[NSString stringWithFormat:@"%ld", tag], @"data":dict};
    NSError *error;
    NSString * message = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error] encoding:NSUTF8StringEncoding];
    [self.eventChannel sendMessageEventChannel:message];
}
#pragma mark - yjSyncData
- (void)onClickUTEOption:(NSInteger)option{
    [[YJDeviceManager sharedInstance] setUTEOption:option];
}

- (void)onClickSyncDataCustom:(NSInteger)option{
    [[YJDeviceManager sharedInstance] syncDataCustomTime:@"2020-08-08-08-08" type:option];
}
- (void)onClickSyncGPSData{
    [[YJDeviceManager sharedInstance] syncDataGPS:@"2020-08-08-08-08"];
}

- (void)onClickSyncUTESportModelCustom{
    [[YJDeviceManager sharedInstance] syncUTESportModelCustomTime:@"2020-01-01-00-00"];
}
#pragma mark - kUTETestMethod
- (void)onClickTestBodyFat:(BOOL)isTest{
    UTEModelDeviceBodyFatConfig *config = [[UTEModelDeviceBodyFatConfig alloc]init];
    config.gender = UTEDeviceInfoSexMale;
    config.age = 20;
    config.height = 170;
    config.weight = 60;
    config.index = 0;
    [[YJDeviceManager sharedInstance].smartBandMgr monitorBodyFat:isTest config:config];
}
- (void)onClickTestECG:(BOOL)isTest{
    [[YJDeviceManager sharedInstance].smartBandMgr monitorECG:isTest];
}
#pragma mark - kUpdateFirmware
- (void)onClickUpdateFirmwareCheck{
    [[YJDeviceManager sharedInstance].smartBandMgr checkUTEFirmwareVersion];
}
- (void)onClickUpdateFirmwareUpate{
    [[YJDeviceManager sharedInstance].smartBandMgr beginUpdateFirmware];
}
#pragma mark - kAppRemind
- (void)onClickAppQQRemind:(NSInteger)option{
    UTEModelDeviceRemindApp *remindApp = [[UTEModelDeviceRemindApp alloc] init];
    remindApp.QQ = option;
    [[YJDeviceManager sharedInstance].smartBandMgr setUTERemindApp:remindApp];
}

- (void)onClickAppMoreRemind:(NSInteger)option{
    UTEModelDeviceRemindApp *remindApp = [[UTEModelDeviceRemindApp alloc] init];
    remindApp.Other = option;
    [[YJDeviceManager sharedInstance].smartBandMgr setUTERemindApp:remindApp];
}

- (void)onClickSitRemind:(BOOL)isOpen{
    UTEModelDeviceSitRemind *model = [[UTEModelDeviceSitRemind alloc] init];
    model.enable = isOpen;
    model.startTime = @"08:00";
    model.endTime = @"23:00";
    model.duration = 60;
    model.enableSiesta = YES;
    [[YJDeviceManager sharedInstance].smartBandMgr sendUTESitRemindModel:model];
}
#pragma mark - kAboutSport
- (void)readUTESportModelStatus{
    if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSportHRM) {
        [[YJDeviceManager sharedInstance].smartBandMgr readUTESportModelStatus:^(UTEDeviceSportMode mode, UTEDeviceSportModeStatus status) {
        }];
    }else if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasHeadsetHRM){
        [[YJDeviceManager sharedInstance].smartBandMgr readUTESportHeadsetModelStatus];
    }
}

- (void)setUTEBicycleSportModel:(BOOL)open{
    if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSportHRM) {
         [[YJDeviceManager sharedInstance].smartBandMgr setUTESportModel:UTEDeviceSportModeCycling open:open hrmTime:UTEDeviceIntervalTime10s callback:^(UTEDeviceSportMode mode, BOOL open) {
           }];
    }else if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasHeadsetHRM){
        [[YJDeviceManager sharedInstance].smartBandMgr setUTESportHeadsetModel:UTEDeviceSportModeCycling open:open hrmTime:10];
    }
}

- (void)setUTBicycleESportModelPause{
    UTEDeviceSportModeInfo *model = [[UTEDeviceSportModeInfo alloc]init];
    model.mode = UTEDeviceSportModeCycling;
    model.status = UTEDeviceSportModeStatusPause;
    //CN:其他值，把app的数据赋值发下去给设备
    //EN:Other values, assign app data to the device
    model.calories = 30;
    model.distance = 300;
    model.duration = 120;
    model.speed = 20;
    model.hrmTime = 10;
    [[YJDeviceManager sharedInstance].smartBandMgr setUTESportModelPause:model];
}

- (void)setUTESportModelContinue{
    UTEDeviceSportModeInfo *model = [[UTEDeviceSportModeInfo alloc]init];
    model.mode = UTEDeviceSportModeCycling;
    model.status = UTEDeviceSportModeStatusContinue;
    //CN:其他值，把app的数据赋值发下去给设备
    //EN:Other values, assign app data to the device
    model.calories = 30;
    model.distance = 300;
    model.duration = 120;
    model.speed = 20;
    model.hrmTime = 10;
    [[YJDeviceManager sharedInstance].smartBandMgr setUTESportModelContinue:model];
}

- (void)setUTESportModelInfo{
    UTEDeviceSportModeInfo *model = [[UTEDeviceSportModeInfo alloc]init];
    model.mode = UTEDeviceSportModeCycling;
    //CN:其他值，把app的数据赋值发下去给设备
    //EN:Other values, assign app data to the device
    model.calories = 35;
    model.distance = 320;
    model.duration = 130;
    model.speed = 20;
    model.hrmTime = 10;
    [[YJDeviceManager sharedInstance].smartBandMgr setUTESportModelInfo:model];
}

#pragma mark - kAboutDial
- (void)readUTEDisplayInfoFormDevice{
    __weak typeof (self) weakSelf = self;
    [[YJDeviceManager sharedInstance].smartBandMgr readUTEDisplayInfoFormDevice:^(UTEModelDeviceDisplayModel * _Nullable model) {
        NSLog(@"Read dial information successfully   %@_%ld_%ld",model.versionName,(long)model.width,(long)model.height);
//        weakSelf.localDisplayModel = model;
//        weakSelf.localDisplayModel.versionName = [YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.versionName;
//        weakSelf.localDisplayModel.language = UTEDeviceLanguageChinese;
    }];
    
}

- (void)getUTEDisplayInfoFormServer{
    
//    self.localDisplayModel.startIndex = 0;
//    self.localDisplayModel.endIndex = 10;
    //CN:拉取在线表盘信息，必须有网络才能成功。
    //要正确的sdkkey，请咨询我司研发
    //EN:To pull online watch face information, you must have a network to succeed.
    //For the correct sdkkey, please consult our R&D
//    [[YJDeviceManager sharedInstance].smartBandMgr getUTEDisplayInfoFormServer:@"e82e5a74c7edeb97009bef38bb06695e" device:self.localDisplayModel success:^(NSArray<UTEModelDeviceDisplayModel *> * modelArray) {
//        //CN:一个model对应一个表盘，model中有固件下载链接，需要去先下载再同步表盘
//        //EN:A model corresponds to a dial, there is a firmware download link in the model, you need to download first and then synchronize the dial
//        NSLog(@"Pull online watch face successfully");
//    } failure:^(NSError *error) {
//        //CN:请确保网络环境正常，参数填写正确
//        //EN:Please ensure that the network environment is normal and the parameters are filled in correctly
//        NSLog(@"Failed to pull online watch face");
//    }];
    
}

- (void)sendUTEDisplayDataToDevice:(NSData *_Nonnull)binDate{
    
    [[YJDeviceManager sharedInstance].smartBandMgr sendUTEDisplayDataToDevice:binDate process:^(CGFloat process) {
        NSLog(@"Dial synchronization progress---%.0f%%",process*100);
    } success:^{
        NSLog(@"Sync watch face successfully");
    } failure:^(NSError * _Nullable error) {
        //CN:请确保bin文件路径存在
        //EN:Please make sure the bin file path exists
        NSLog(@"Failed to sync watch face");
    }];
    
}

- (void)getUTECustomDialDefualtInfo{
    
//    NSArray<UTEModelDialInfo *> *modelArray = [self.smartBandMgr getUTECustomDialDefualtInfo:self.localDisplayModel];
//    self.localDialInfoModel = modelArray.firstObject;
//    if (self.localDialInfoModel) {
//        NSLog(@"Successfully obtained local custom watch face---%ld---",(long)self.localDialInfoModel.index);
//    }else{
//        NSLog(@"Failed to get local custom watch face");
//    }
    
}

- (void)getUTECustomDialInfoFromServer{
    
    //CN:拉取在线自定义表盘，必须有网络才能成功。
    //EN:To pull online custom watch faces, you must have an internet connection to succeed.
    //CN:要正确的sdkkey，请咨询我司研发
    //CN:For the correct sdkkey, please consult our R&D
//    [[YJDeviceManager sharedInstance].smartBandMgr getUTECustomDialInfoFromServer:@"e82e5a74c7edeb97009bef38bb06695e" device:self.localDisplayModel success:^(NSArray<UTEModelDialServer *> * _Nullable zipDials) {
//        //CN:一个model对应一个zip包，model中有下载链接，需要去先下载再解压才能下一步使用
//        //EN:A model corresponds to a zip package, and there is a download link in the model. You need to download and unzip it before you can use it in the next step.
//        NSLog(@"Succeeded in pulling online custom watch face");
//    } failure:^{
//        //CN:请确保网络环境正常，参数填写正确
//        //EN:Please ensure that the network environment is normal and the parameters are filled in correctly
//        NSLog(@"Failed to pull online custom watch face");
//    }];
    
}

- (void)getUTECustomDialInfoFromUnzippedPath{
    
    //CN:path:zip包解压后的路径
    //EN:path:The path of the zip package after decompression
//    NSArray<UTEModelDialInfo *> *modelArray = [[YJDeviceManager sharedInstance].smartBandMgr getUTECustomDialInfoFromUnzippedPath:@"/var/mobile/Containers/Data/Application/xxxxx/" defaultInfo:self.localDisplayModel];
//    self.serverDialInfoModel = modelArray.firstObject;
//    if (self.serverDialInfoModel) {
//        NSLog(@"Successfully converted online custom watch face---%ld---",(long)self.serverDialInfoModel.index);
//    }else{
//        NSLog(@"Failed to convert online custom watch face");
//    }
    
}

- (void)changeUTEDialBackgroundImage{
    
    //CN:image 自定义image，fontcolor 自定义fontcolor，imgage = nil恢复默认状态
    //EN:image customize image，fontcolor customize fontcolor，imgage = nil Restore default state
//    [[YJDeviceManager sharedInstance].smartBandMgr changeUTEDialBackgroundImage:nil fontColor:nil dialIndex:self.localDialInfoModel.index success:^(UTEModelDialInfo * _Nullable dialInfo) {
//        //CN:这里保存model，更新预览图
//        //EN:Save the model here, update the preview
//        NSLog(@"Modify the custom preview image successfully");
//    } failure:^{
//        NSLog(@"Failed to modify custom preview image");
//    }];
    
}
#pragma mark - kAboutRespiration
- (void)startTestRespirationRate{
    [[YJDeviceManager sharedInstance].smartBandMgr setRespirationAutoTest:YES time:UTECommonTestTime10Mins];
}

- (void)stopTestRespirationRate{
    [[YJDeviceManager sharedInstance].smartBandMgr setRespirationAutoTest:NO time:UTECommonTestTime10Mins];
}

- (void)readRespirationRateTestStatus{
    [[YJDeviceManager sharedInstance].smartBandMgr readRespirationStatus:^(BOOL isDetecting) {
        
    }];
}

- (void)startRespirationRateCustomTestTime{
    //CN:open如果为YES，则会在startTime和endTime之间自动测试呼吸。
    //EN:open If YES,Respiration is automatically test between startTime and endTime.
    [[YJDeviceManager sharedInstance].smartBandMgr setRespirationAutoTestDuration:YES startTime:@"09:00" endTime:@"21:00"];
}

- (void)closeRespirationRateCustomTestTime{
    //CN:open如果为NO，则全天进行呼吸测试。
    //EN:open If NO,Respiration testing throughout the day.
    [[YJDeviceManager sharedInstance].smartBandMgr setRespirationAutoTestDuration:NO startTime:@"09:00" endTime:@"21:00"];
}
#pragma mark - kOther
- (void)setDevicesAlarm{
    UTEModelAlarm *model1 = [[UTEModelAlarm alloc] init];
    model1.time     = @"20:07";
    model1.week     = UTEAlarmWeekMonday|UTEAlarmWeekTuesday|UTEAlarmWeekWednesday
    |UTEAlarmWeekThursday|UTEAlarmWeekFriday|UTEAlarmWeekSaturday|UTEAlarmWeekSunday;
    model1.enable   = NO;
    model1.num      = UTEAlarmNum1;
    model1.countVibrate = 5;
    
    UTEModelAlarm *model2 = [[UTEModelAlarm alloc] init];
    model2.time     = @"20:08";
    model2.week     = UTEAlarmWeekMonday|UTEAlarmWeekTuesday|UTEAlarmWeekWednesday
    |UTEAlarmWeekThursday|UTEAlarmWeekFriday|UTEAlarmWeekSaturday|UTEAlarmWeekSunday;
    model2.enable   = NO;
    model2.num      = UTEAlarmNum2;
    model2.countVibrate = 10;
    
    UTEModelAlarm *model3 = [[UTEModelAlarm alloc] init];
    model3.time     = @"15:22";
    model3.week     = UTEAlarmWeekMonday|UTEAlarmWeekTuesday|UTEAlarmWeekWednesday
    |UTEAlarmWeekThursday|UTEAlarmWeekFriday|UTEAlarmWeekSaturday|UTEAlarmWeekSunday;
    model3.enable   = YES;
    model3.num      = UTEAlarmNum3;
    model3.countVibrate = 10;
    
    [[YJDeviceManager sharedInstance].smartBandMgr setUTEAlarmArray:@[model1,model2,model3] vibrate:5];
    
}

- (void)setHeightWeightInfo{
    
    UTEModelDeviceInfo *info = [[UTEModelDeviceInfo alloc] init];
    info.heigh          = 175;
    info.weight         = 65;
    info.lightTime      = 15;
    info.sportTarget    = 8000;
    info.handlight      = YES;
    
    if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasMaxHeartAlert) {
        info.maxHeart       = 255;
    }
    
    if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasMinHeartAlert) {
        info.minHeart       = 50;
    }
    
    if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSleepAux) {
        info.sleepAux = UTEDeviceSleepAuxTypeOpen;
    }
    
    info.age            = 24;
    info.sex            = UTEDeviceInfoSexFemale;
    
    if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSmartLost) {
        info.isSmartLost = NO;
    }
    
    if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSwitchCH_EN) {
        info.languageIsChinese = YES;
    }
    
    if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasSwitchTempUnit) {
        info.isFahrenheit = YES;
    }
    
    [[YJDeviceManager sharedInstance].smartBandMgr setUTEInfoModel:info];
        
}



- (void)setDevicesInterfaceText{
    
    if ([YJDeviceManager sharedInstance].smartBandMgr.connectedDevicesModel.isHasLanguageSwitchDirectly) {
        [[YJDeviceManager sharedInstance].smartBandMgr setUTELanguageSwitchDirectly:UTEDeviceLanguageChinese];
    }else{
        UTEModelDeviceInterface *interModel = [[UTEModelDeviceInterface alloc] init];
        //CN:interModel.num1Step 不设置，看注释默认为 Step，以此类推，需要设置，请重新设置。
        //EN:interModel.num1Step If you don't set it, see the comment by default as Step, and so on, you need to set it, please reset it.
        interModel.language         = UTEDeviceLanguageChinese;
        interModel.num1Step         = @"步数";
        interModel.num2KM           = @"千米";
        interModel.num3KCAL         = @"卡路里";
        interModel.num4Reading      = @"正在识别";
        interModel.num5Training     = @"锻炼";
        interModel.num6Skipping     = @"游泳";
        interModel.num7Swiming      = @"跳绳";
        interModel.num8Message      = @"短信";
        interModel.num9Function     = @"功能";
        interModel.num10Dial        = @"表盘更换";
        interModel.num11Information = @"信息";
        interModel.num12Restore     = @"恢复出厂";
        interModel.num13Poweroff    = @"关机";
        interModel.num14Refused     = @"拒接";
        interModel.num15Version     = @"版本";
        [[YJDeviceManager sharedInstance].smartBandMgr setUTELanguageInterface:interModel];
    }
    
}

- (void)adjustSleepInfo{
    
    UTEModelDeviceSleepAdjust *param = [[UTEModelDeviceSleepAdjust alloc] init];
    
    //CN:设置 晚上睡眠时间范围
    //EN:Set night sleep time range
    param.timeDurationSet       = YES;
    param.timeDurationType      = UTEDeviceSleepTimeTypeNight;
    param.timeDurationStatus    = UTEDeviceSleepStatusOpen;
    param.timeDurationStart     = @"23:00";
    param.timeDurationEnd       = @"07:00";
    
    //CN:手环自动智能检测晚上睡眠
    //EN:The bracelet automatically detects sleep at night
//    param.timeDurationSet       = YES;
//    param.timeDurationType      = UTEDeviceSleepTimeTypeNight;
//    param.timeDurationStatus    = UTEDeviceSleepStatusClose;
    
    //CN:设置 午睡睡眠时间范围
    //EN:Set nap sleep time range
//    param.timeDurationSet       = YES;
//    param.timeDurationType      = UTEDeviceSleepTimeTypeSiesta;
//    param.timeDurationStatus    = UTEDeviceSleepStatusOpen;
//    param.timeDurationStart     = @"13:00";
//    param.timeDurationEnd       = @"14:00";
    
    //CN:关闭手环午睡监测
    //EN:Turn off the wristband nap monitoring
//    param.timeDurationSet       = YES;
//    param.timeDurationType      = UTEDeviceSleepTimeTypeSiesta;
//    param.timeDurationStatus    = UTEDeviceSleepStatusClose;

    /**
        CN:例子: 昨晚睡眠监测为 23:00 ~ 07:00
        矫正手环晚上睡眠的监测不准, 必须有了昨天睡眠才能校验,今晚生效
     
        EN:Example: The sleep monitoring last night was 23:00 ~ 07:00
        The monitoring of sleep at night for the correction bracelet is inaccurate, you must have yesterday’s sleep to verify it, and it will take effect tonight
    */
    
    //CN:如开始睡眠不对 要矫正睡眠起始点
    //EN:If you start to sleep incorrectly, correct the starting point of sleep
    
    //CN:原来睡眠的开始时间
    //EN:Original sleep start time
    param.timeAdjustStartTimeDefault    = @"00:00";
    //CN:用户觉得他 22:00 开始睡觉
    //EN:The user thinks he starts to sleep at 22:00
    param.timeAdjustStartTimeChange     = @"22:00";
    //CN:矫正的是睡眠开始时间
    //EN:The correction is the sleep start time
    param.timeAdjustStartTimeSet        = YES;

    //CN:如结束睡眠不对 要矫正睡眠结束点
    //EN:If the end of sleep is wrong, correct the end of sleep
    
    //CN:原来睡眠的结束时间
    //EN:Original end time of sleep
    param.timeAdjustEndTimeDefault      = @"06:00";
    //CN:用户觉得他 08:00 睡觉结束
    //EN:The user thinks that his sleep ends at 08:00
    param.timeAdjustEndTimeChange       = @"08:00";
    //CN:矫正的是睡眠结束时间
    //EN:The correction is the end of sleep time
    param.timeAdjustEndTimeSet          = YES;
    
    [[YJDeviceManager sharedInstance].smartBandMgr setUTESleepAdjustParam:param];
    
}

- (void)adjustSleepInfoNight{
    
    UTEModelDeviceSleepAdjust *param = [[UTEModelDeviceSleepAdjust alloc] init];
    
    //CN:设置 晚上睡眠 时间范围
    //EN:Set night sleep time range
    param.timeDurationSet       = YES;
    param.timeDurationType      = UTEDeviceSleepTimeTypeNight;
    param.timeDurationStatus    = UTEDeviceSleepStatusOpen;
    param.timeDurationStart     = @"22:00";
    param.timeDurationEnd       = @"09:00";
    
    [[YJDeviceManager sharedInstance].smartBandMgr setUTESleepAdjustParam:param];
    
}

- (void)adjustSleepInfoSiesta{
    
    UTEModelDeviceSleepAdjust *param = [[UTEModelDeviceSleepAdjust alloc] init];
    
    //CN:设置 午睡 时间范围
    //EN:Set nap time range
    param.timeDurationSet       = YES;
    param.timeDurationType      = UTEDeviceSleepTimeTypeSiesta;
    param.timeDurationStatus    = UTEDeviceSleepStatusOpen;
    param.timeDurationStart     = @"13:00";
    param.timeDurationEnd       = @"14:00";
    
    [[YJDeviceManager sharedInstance].smartBandMgr setUTESleepAdjustParam:param];
    
}

- (void)sendCustomData{
    
    Byte b[48] = {0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,
               0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,
               0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa1,0xa2};
    
    NSData *sendData = [NSData dataWithBytes:&b length:48];
    [[YJDeviceManager sharedInstance].smartBandMgr sendUTECustomData:sendData flagSync:NO];

}

- (void)sendMenstruationRemind{
    
    UTEModelDeviceMenstruation *model = [[UTEModelDeviceMenstruation alloc]init];
    model.firstTime = @"2020-08-08";
    model.duration = 5;
    model.cycle = 28;
    model.openReminder = YES;
    [[YJDeviceManager sharedInstance].smartBandMgr sendMenstruationRemind:model];
    
}

- (void)setUTEDeviceCustomUIStatus{
    
    //CN:隐藏跳绳页面
    //EN:Hide skipping page
    UTEModelDeviceCustomUI *model = [[UTEModelDeviceCustomUI alloc]init];
    model.ui = UTEDeviceCustomUITypeRopeSkipping;
    model.show = NO;
    [[YJDeviceManager sharedInstance].smartBandMgr setUTEDeviceCustomUIStatus:@[model]];
    
}

- (void)sendUTECustomMsg{
    
    UTEModelDeviceCustomMsg *model = [[UTEModelDeviceCustomMsg alloc]init];
    model.type = UTEDeviceMsgTypeOther;
    model.msg = @"WhatsApp: Hello ,I'm hungry!";
//    model.sender  = @"UET";
    [[YJDeviceManager sharedInstance].smartBandMgr sendUTECustomMsg:model];
    
}

- (void)readUTEDeviceVersion{
    
    [[YJDeviceManager sharedInstance].smartBandMgr readUTEDeviceVersion];
    
}

- (void)readUTEDeviceAddress{
    
    [[YJDeviceManager sharedInstance].smartBandMgr readUTEDeviceAddress];
    
}

- (void)readDeviceLanguage{
    
    [[YJDeviceManager sharedInstance].smartBandMgr readDeviceLanguage:^(UTEDeviceLanguage language) {
        
    }];
    
}

- (void)calibrateBodyTemp{
    
    [[YJDeviceManager sharedInstance].smartBandMgr calibrateBodyTemp:@"16.55" complete:^(BOOL success) {
        
    }];
    
}

- (void)setBodyTemperatureAutoTest{
    
    [[YJDeviceManager sharedInstance].smartBandMgr setBodyTemperatureAutoTest:YES time:UTECommonTestTime1Hour];
    
}

- (void)setBodyTemperatureAutoTestDuration{
    
    [[YJDeviceManager sharedInstance].smartBandMgr setBodyTemperatureAutoTestDuration:YES startTime:@"09:00" endTime:@"19:00"];
    
}

- (void)setBodyTemperatureAlarmOpen{
    
    [[YJDeviceManager sharedInstance].smartBandMgr setBodyTemperatureAlarmOpen:YES max:37.3 alarmMin:42];
    
}

- (void)readBodyTemperatureCurrent{
    
    [[YJDeviceManager sharedInstance].smartBandMgr readBodyTemperatureCurrent];
    
}

- (void)retrieveConnectedDeviceWithServers{
    
    NSArray<UTEModelDevices *> * modelArray = [[YJDeviceManager sharedInstance].smartBandMgr retrieveConnectedDeviceWithServers:@[@"5533"]];
    UTEModelDevices *model = modelArray.firstObject;
    NSLog(@"%@-%@,",model.versionName,model.addressStr);
    
}

- (void)setBloodOxygenAutoTest{
    [[YJDeviceManager sharedInstance].smartBandMgr setBloodOxygenAutoTest:YES time:UTECommonTestTime10Mins];
}

- (void)setBloodOxygenAutoTestDuration{
    [[YJDeviceManager sharedInstance].smartBandMgr setBloodOxygenAutoTestDuration:YES startTime:@"09:00" endTime:@"22:00"];
}

- (void)getSportSupport
{
    [[YJDeviceManager sharedInstance].smartBandMgr readUTESportModelSupport:^(NSInteger minDisplay, NSInteger maxDisplay, NSArray<NSNumber *> * _Nullable array) {
        NSLog(@"...");
    }];
}

- (void)getSportCurrent
{
    [[YJDeviceManager sharedInstance].smartBandMgr readUTESportModelCurrentDisplay:^(NSArray<NSNumber *> * _Nullable array) {
        NSLog(@"...");
    }];
}

- (void)setSportCurrent
{
    NSArray *array = @[[NSNumber numberWithInteger:UTEDeviceSportModeDance],[NSNumber numberWithInteger:UTEDeviceSportModeWalking],[NSNumber numberWithInteger:UTEDeviceSportModeRunning]];
    [[YJDeviceManager sharedInstance].smartBandMgr setUTESportModelCurrentDisplay:array callback:^(BOOL success, NSInteger errorCode) {
            NSLog(@"...");
    }];
}


@end
